package com.upstairstechnology.oi.determination;

import java.util.Date;
import java.util.Set;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * An outstanding integration.
 * 
 * @author Jeff Jensen
 */
public class OutstandingIntegration implements
        Comparable<OutstandingIntegration> {
    /** SCM User that made the original change. */
    private String userId;

    /** Check that was run to obtain these outstanding integrations. */
    private IntegrationCheck integrationCheck;

    /** Unique SCM id of the change. Not all SCMs have this. */
    private String changeNum;

    /** Set of files committed in the change that need integrating. */
    private Set<OutstandingIntegration.File> files;

    /** Date & time of the change. */
    private Date timestamp;

    /** SCM client/workspace used for the commit. Not all SCMs have this. */
    private String client;

    /** SCM commit comment. */
    private String comment;

    /** An outstanding integration file. */
    public static class File implements Comparable<File> {
        /** The file that needs integrating, including full path information. */
        private String name;

        /**
         * The SCM action on the file, e.g. add, edit. Not all SCMs will report
         * this.
         */
        private String action;

        /**
         * {@inheritDoc}
         */
        public int compareTo(File o) {
            int comparedValue = CompareToBuilder.reflectionCompare(this, o);
            return comparedValue;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean equals(Object o) {
            boolean isEqual = EqualsBuilder.reflectionEquals(this, o);
            return isEqual;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public int hashCode() {
            int hc = HashCodeBuilder.reflectionHashCode(this);
            return hc;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return ToStringBuilder.reflectionToString(this);
        }

        /**
         * Get the file name.
         * 
         * @return The file name.
         */
        public String getName() {
            return name;
        }

        /**
         * Set the file name.
         * 
         * @param fileName
         *            The file name.
         */
        public void setName(String fileName) {
            this.name = fileName;
        }

        /**
         * Get the SCM action.
         * 
         * @return The SCM action.
         */
        public String getAction() {
            return action;
        }

        /**
         * Set the SCM action.
         * 
         * @param scmAction
         *            The SCM action.
         */
        public void setAction(String scmAction) {
            this.action = scmAction;
        }
    }

    /**
     * {@inheritDoc}
     */
    public int compareTo(OutstandingIntegration o) {
        int comparedValue = CompareToBuilder.reflectionCompare(this, o);
        return comparedValue;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object o) {
        boolean isEqual = EqualsBuilder.reflectionEquals(this, o);
        return isEqual;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        int hc = HashCodeBuilder.reflectionHashCode(this);
        return hc;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    /**
     * Get the change number.
     * 
     * @return The changeNum.
     */
    public String getChangeNum() {
        return changeNum;
    }

    /**
     * Set the change number.
     * 
     * @param change
     *            The changeNum to set.
     */
    public void setChangeNum(String change) {
        this.changeNum = change;
    }

    /**
     * Get the integration check.
     * 
     * @return The integration check.
     */
    public IntegrationCheck getIntegrationCheck() {
        return integrationCheck;
    }

    /**
     * Set the integration check.
     * 
     * @param integrationCheck
     *            The integration check.
     */
    public void setIntegrationCheck(IntegrationCheck integrationCheck) {
        this.integrationCheck = integrationCheck;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getClient() {
        return client;
    }

    public void setClient(String client) {
        this.client = client;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Set<OutstandingIntegration.File> getFiles() {
        return files;
    }

    public void setFiles(Set<OutstandingIntegration.File> files) {
        this.files = files;
    }
}
